#include "checkcodewidget.h"

#include<QMessageBox>
#include<QFile>
#include<QLineEdit>
#include<QHBoxLayout>
#include<QSpacerItem>
#include<QLabel>
#include<QPushButton>
#include<QApplication>
#include<qDebug>
#include<QProcess>
#include"windows.h"
#include"shellapi.h"
#include"Winbase.h"
#include<QDateTime>
#include<QThread>
#define MYLOG qDebug() << "[" << __FILE__ << ":" << __LINE__ << ":" << QThread::currentThread() << __func__ << QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss:zzz")<< "]"
CheckCodeWidget::CheckCodeWidget(QWidget *parent) :
  QWidget(parent,Qt::WindowStaysOnTopHint)
{

  create();

  connect(btn1,SIGNAL(clicked()),this,SLOT(btn1Slots()));

  connect(btn2,SIGNAL(clicked()),this,SLOT(btn2Slots()));

}

CheckCodeWidget::~CheckCodeWidget()
{
  delete lineEdit;
  lineEdit = nullptr;
  delete btn1;
  btn1 = nullptr;
  delete btn2;
  btn2 = nullptr;
}

void CheckCodeWidget::create()
{
  setWindowTitle("校准程序");
  setFixedSize(650,200);

  QLabel *label = new QLabel("编号:",this);

  lineEdit = new QLineEdit("1",this);
  lineEdit->setFixedSize(70,60);

  lineEdit->setReadOnly(true);
  lineEdit->setAlignment(Qt::AlignCenter);

  btn1 = new QPushButton("开始校准",this);
  btn1->setFixedSize(180,60);

  btn2 = new QPushButton("结束",this);
  btn2->setFixedSize(180,60);

  //弹簧
  QSpacerItem *h_spacer = new QSpacerItem(10,10,QSizePolicy::Expanding,QSizePolicy::Minimum);

  QHBoxLayout *layout= new QHBoxLayout(this);
  layout->addItem(h_spacer);
  layout->addWidget(label);
  layout->addItem(h_spacer);
  layout->addWidget(lineEdit);
  layout->addItem(h_spacer);
  layout->addWidget(btn1);
  layout->addItem(h_spacer);
  layout->addWidget(btn2);
  layout->addItem(h_spacer);
  setLayout(layout);
  setStyleSheet("QLabel,QPushButton,QLineEdit{width: 100px;height: 100px;font-size: 30px;font-bold;font-family: 微软雅黑;}");
}

void CheckCodeWidget::btn1Slots()
{

  btn1->setEnabled(false);
  btn1->setText("正在校准...");

  emit mySignalBegin(flag);
}

void CheckCodeWidget::btn2Slots()
{
  btn1->setEnabled(true);
  btn1->setText("开始校准");

  emit mySignalOver(flag);
}

void CheckCodeWidget::getCurrentIndex(int index)
{
  flag = index;

  lineEdit->setText(QString::number(flag));

}


